package com.ruoyi.merchant.component;

import com.ruoyi.merchant.service.IShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @ClassName ShopSyncScheduler
 * @Description TODO
 * @Author WGH
 * @Date 2025年09月18日 16:36
 * @Version 1.0
 */
@Component
@Slf4j
public class ShopSyncScheduler {
    @Resource
    private IShopService shopService;

    @Scheduled(cron = "0 0 */2 * * ?")
    @ConditionalOnProperty(name = "shop.sync.enabled", havingValue = "true", matchIfMissing = false)
    public void syncShopsToEs() {
        log.info("===== 开始定时同步商铺数据到 Elasticsearch =====");
        try {
            shopService.syncShopsToEs();
            log.info("===== 定时同步完成 =====");
        } catch (Exception e) {
            log.error("===== 定时同步失败 =====", e);
        }
    }

}
